﻿using System;
using System.Net.Sockets;

namespace Ping.Core
{
	/// <summary>
	/// An exception that is thrown in case a job could not be performed.
	/// This is a superclass for several kinds of errors:
	/// -Error while reading the Request
	/// -Error while performing the job
	/// </summary>
	/// <remarks>
	/// This exception should be thrown to report non-critical errors.
	/// </remarks>
	public class ServerOperationException
		: Exception
	{
		public ServerOperationException(string message, Exception inner)
			: base(message, inner)
		{}
	}

	public class SocketException
		: Exception
	{
		public SocketException(SocketError error)
			: base(string.Format("An error occured while performing a socket operation: {0}", error))
		{}
	}

	/// <summary>
	/// An exception that is thrown in case a connection must be aborted because it
	/// does not behave in the desired way.
	/// </summary>
	public class ConnectionAbortException
		: Exception
	{
		public ConnectionAbortException()
			: base("Aborting connection because it doesn't meet the requiremets")
		{}

		public ConnectionAbortException(string message)
			: base(string.Format("Aborting connection because it doesn't meet the requiremets: {0}", message))
		{ }
	}

	public class ConnectionClosedException
		: Exception
	{
		public ConnectionClosedException()
			: base("The connection has been closed by the remote endpoint")
		{}
	}

	/// <summary>
	/// An exception that notifies that reading a particular request didn't work.
	/// </summary>
	public class ReadRequestException
		: Exception
	{
		public ReadRequestException()
			: base("The request could not be extracted from the stream")
		{}

		public ReadRequestException(string message)
			: this(message, null)
		{}

		public ReadRequestException(string message, Exception inner)
			: base(string.Format("The request could not be extracted from the stream: {0}", message), inner)
		{}

		public ReadRequestException(Exception inner)
			: base("The request could not be extracted from the stream", inner)
		{}
	}
}